import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  // 基于command模式不同来决定选项 serve build dev
  const env = loadEnv(mode, process.cwd(), '')
  return {
    resolve: {
      alias: {
        '@': resolve(__dirname, "./src"),
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
      }
    },
    plugins: [vue()],
    server: {
      host: "0.0.0.0", // 解决vite use--host to expose
      open: true,
      cors: true,
      proxy: {
        '/service':{
          target: 'http://localhost:7000/',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/service/, '')
        }
      }
    },
    build: {
      sourcemap: true
    },
  }
})
